package 力扣日常刷题.木23一月.第07天307;

/**
 * @author 帅小伙
 * @date 2022/3/7
 * @description
 */
public class Demo07七进制数 {


    public String convertToBase7(int num) {
        if(num ==0) return "0";
        boolean negative = num < 0;
        num = Math.abs(num);
        StringBuffer digits = new StringBuffer();
        while(num > 0) {
            digits.append(num % 7);
            num /= 7;
        }
        if (negative) digits.append('-');
        return digits.reverse().toString();
    }

}
